import 'package:flutter/material.dart';
import '../../l10n/app_localizations.dart';

class OcouponPopView extends StatelessWidget {
  final Function() onCouponPress;
  final Function() close;

  OcouponPopView({required this.onCouponPress, required this.close});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Dialog(
        backgroundColor: Colors.transparent,
        child: Center(
          child: Container(
            width: 350,
            height: 300,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage( isChineseLocale() ? 'assets/images/coupon1.png' : 'assets/images/coupon1en.png'),
                fit: BoxFit.fill,
              ),
            ),
            child: Stack(
              children: [
                // 关闭按钮
                Positioned(
                  top: 15,
                  right: 15,
                  child: GestureDetector(
                    onTap: close,
                    child: Image.asset(
                      'assets/images/coupon2.png',
                      width: 30,
                      height: 30,
                    ),
                  ),
                ),
                // 查看优惠券按钮
                Positioned(
                  bottom: 45,
                  left: 50,
                  child: _buildButton(
                    label: AppLocalizations.of(context)!.viewCoupon,
                    gradientStartColor: Color(0xFFFF8008),
                    gradientEndColor: Color(0xFFFFC837),
                    onPressed: onCouponPress,
                  ),
                ),
                // 去购物按钮
                Positioned(
                  bottom: 45,
                  right: 55,
                  child: _buildButton(
                    label: AppLocalizations.of(context)!.goShopping,
                    gradientStartColor: Color(0xFFEB3349),
                    gradientEndColor: Color(0xFFFB6F40),
                    onPressed: close,
                  ),
                ),
                // 显示优惠券张数
                Positioned(
                  bottom: isChineseLocale() ? 105 : 110,
                  right: isChineseLocale() ? 60 : 54,
                  child: Text(
                    isChineseLocale() ? '张' : 'items',
                    style: TextStyle(
                      fontSize: isChineseLocale() ? 22 : 14,
                      color: Colors.red,
                    ),
                  ),
                ),
                // 显示价格
                Positioned(
                  bottom: 100,
                  right: 90,
                  child: Text(
                    _price(),
                    style: TextStyle(
                      fontSize: 38,
                      color: Colors.red,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                // 竖线
                Positioned(
                  bottom: 120,
                  right: 130,
                  child: Container(
                    height: 35,
                    width: 1,
                    color: Color(0xFFCD9C73),
                  ),
                ),
                // 说明文本
                Positioned(
                  bottom: 100,
                  left: 50,
                  child: Text(
                    AppLocalizations.of(context)!.useNowDiscount,
                    style: TextStyle(
                      fontSize: 16,
                      color: Colors.red,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  // 价格文本内容
  String _price() {
    return "5"; // 默认显示的价格
  }

  // 渐变按钮的构建方法
  Widget _buildButton({
    required String label,
    required Color gradientStartColor,
    required Color gradientEndColor,
    required VoidCallback onPressed,
  }) {
    return Container(
      width: 95,
      height: 32,
      decoration: BoxDecoration(
        boxShadow: [
          BoxShadow(
            color: Color(0xFFC1411F),
            blurRadius: 15,
            offset: Offset(0, 3),
          ),
        ],
      ),
      child: ElevatedButton(
        style: ButtonStyle(
          padding: MaterialStateProperty.all(EdgeInsets.zero),
          backgroundColor: MaterialStateProperty.all(Colors.transparent),
          shape: MaterialStateProperty.all(RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          )),
        ),
        onPressed: onPressed,
        child: Ink(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [gradientStartColor, gradientEndColor],
            ),
            borderRadius: BorderRadius.circular(17),
          ),
          child: Container(
            alignment: Alignment.center,
            child: Text(
              label,
              style: TextStyle(color: Colors.white, fontSize: 15),
            ),
          ),
        ),
      ),
    );
  }
}
